<?php 

namespace VSF\Form;

use \Zend\Form\Form as ZendForm;
use \Zend\InputFilter\InputFilter;
use \Zend\InputFilter\Factory as InputFilterFactory;


class Form extends ZendForm
{
	public function __construct($config = array())
	{
		/*
		 * Parse Config
		 */
		$formName 	  = isset($config['name']) ? $config['name'] : null;
		$formOptions  = isset($config['options']) ? $config['options'] : array();
		$formMethod   = isset($config['method']) ? $config['method'] : 'get';
		$formAction   = isset($config['action']) ? $config['action'] : '';
		$formElements = isset($config['elements']) ? $config['elements'] : array();
		
		/*
		 * Initialize Zend Form
		 */
		parent::__construct($formName, $formOptions);
		$this->setAttribute('method', $formMethod);
		$this->setAttribute('action', $formAction);
		
		/*
		 * Add Elements and Input Filters
		 */
		$inputFilter = new InputFilter();
		$factory = new InputFilterFactory();
		foreach($formElements as $element) {
			$this->add($element);
			
			if($element instanceof Zend\InputFilter\InputInterface) {
				$inputFilter->add($factory->createInput($element));
			}
			
		}
		$this->setInputFilter($inputFilter);
		
		
	}
}
